﻿using Lamex.Base;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lamex.mIE.Calculate
{
    public class LGC_VAL_BOM_SUB1
    {
        /// <summary>
        /// 子程序1
        /// </summary>
        /// <param name="Feature_CheckA">检查特征A</param>
        /// <param name="Feature_CheckB">检查特征B</param>
        /// <param name="H">高度</param>
        /// <param name="dt_BOM">BOM表</param>
        public static DataTable LGC_VAL_BOM_SUB1_VALUE(string Feature_CheckA, string Feature_CheckB, double L_VALUE,
            DataTable dt_BOM, string DWG_No, string Part_No, string Process_Code, string WORKTIME_LOGIC_CODE)
        {
            DataTable dtFeature_List = Common.GetTable.GetTable_Feature();
            double Feature_CheckA_VALUE = 0, Feature_CheckB_VALUE = 0;
            double L = 0;
            if (dt_BOM.Rows.Count > 0)
            {
                for (int i = 0; i < dt_BOM.Rows.Count; i++)
                {
                    //图纸号不为空才执行
                    if (dt_BOM.Rows[i]["DRAWING_NO"].ToString().Trim().Length <= 0)
                        continue;
                    //根据BOM部件号COMPONENT查询得到尺寸参数L,【IE_Part_SizeParmList】
                    DataTable dtTemp = BaseBuildSql.GetDataTableBySql("select LENGTH from IE_Part_SizeParmList where PART_NO='" + dt_BOM.Rows[i]["COMPONENT"].ToString() + "'");
                    //if (dtTemp.Rows.Count <= 0)
                    //L = 0;
                    if (dtTemp.Rows.Count <= 0 || dtTemp.Rows[0]["LENGTH"].ToString().Trim().Length <= 0)
                        continue;
                    else
                        L = dtTemp.Rows[0]["LENGTH"].ToString().Length > 0 ?
                           Convert.ToDouble(dtTemp.Rows[0]["LENGTH"].ToString()) : 0;
                    double SINGLE_QTY = dt_BOM.Rows[i]["SINGLE_QTY"].ToString().Length > 0 ?
                        Convert.ToDouble(dt_BOM.Rows[i]["SINGLE_QTY"].ToString()) : 0;
                    if (L <= L_VALUE)

                        Feature_CheckA_VALUE = Feature_CheckA_VALUE + SINGLE_QTY;
                    else
                        Feature_CheckB_VALUE = Feature_CheckB_VALUE + SINGLE_QTY;
                }
                if (Feature_CheckA_VALUE > 0)
                {
                    DataRow dr = dtFeature_List.NewRow();
                    dr["DWG_NO"] = DWG_No;
                    dr["PART_NO"] = Part_No;
                    dr["PROCESS_CODE"] = Process_Code;
                    dr["FEATURE_NAME"] = Feature_CheckA;
                    dr["FEAT_VALUE"] = Feature_CheckA_VALUE;
                    dr["LABOR_VALUE"] = Calculate.LGC_TIM_VTA.LGC_TIM_VTA_VALUE(DWG_No, Part_No, Feature_CheckA, "", Feature_CheckA_VALUE);//根据特征定义表工时字段计算
                    dr["UPDATE_TIME"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                    dr["UPDATE_USER"] = Lamex.Common.Loginer.CurrentUser.AccountName;
                    dtFeature_List.Rows.Add(dr);
                }
                if (Feature_CheckB_VALUE > 0)
                {
                    DataRow dr1 = dtFeature_List.NewRow();
                    dr1["DWG_NO"] = DWG_No;
                    dr1["PART_NO"] = Part_No;
                    dr1["PROCESS_CODE"] = Process_Code;
                    dr1["FEATURE_NAME"] = Feature_CheckB;
                    dr1["FEAT_VALUE"] = Feature_CheckB_VALUE;
                    dr1["LABOR_VALUE"] = Calculate.LGC_TIM_VTA.LGC_TIM_VTA_VALUE(DWG_No, Part_No, Feature_CheckB, "", Feature_CheckB_VALUE);//根据特征定义表工时字段计算
                    dr1["UPDATE_TIME"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                    dr1["UPDATE_USER"] = Lamex.Common.Loginer.CurrentUser.AccountName;
                    dtFeature_List.Rows.Add(dr1);
                }
            }
            return dtFeature_List;
        }
    }
}
